package com.opNaga.bpmp.basicTest;

import com.opNaga.bpmp.flowObject.activity.Task;
import com.opNaga.bpmp.swimlane.Lane;
import com.opNaga.bpmp.swimlane.Pool;
import org.junit.Assert;
import org.junit.Test;

/**
 * User: Junyi BEI
 * Date: 30/01/2012
 * Time: 12:28
 */
public class CreateContainer {
  @Test
  public void createPool() {
    Pool pool = new Pool();
    Assert.assertNotNull(pool);
  }

  @Test
  public void createLane() {
    Lane lane = new Lane();
    Assert.assertNotNull(lane);
  }

  @Test
  public void addSingleLaneToPool() {
    Pool pool = new Pool();
    Lane lane = new Lane();
    Assert.assertTrue(pool.addLane(lane));
    Assert.assertTrue(pool.includes(lane));
    Assert.assertEquals(pool, lane.getParent());
  }

  @Test
  public void addMultipleLaneToPool() {
    Pool pool = new Pool();
    Lane lane1 = new Lane();
    Assert.assertTrue(pool.addLane(lane1));
    Assert.assertTrue(pool.includes(lane1));
    Lane lane2 = new Lane();
    Assert.assertTrue(pool.addLane(lane2));
    Assert.assertTrue(pool.includes(lane2));
    Lane lane3 = new Lane();
    Assert.assertTrue(pool.addLane(lane3));
    Assert.assertTrue(pool.includes(lane3));
  }

  @Test
  public void rejectDuplicatedLaneInSinglePool() {
    Pool pool = new Pool();
    Lane lane = new Lane();
    Assert.assertTrue(pool.addLane(lane));
    pool.mute();
    lane.mute();
    Assert.assertFalse(((Pool) pool.mute()).addLane(lane));
  }

  @Test
  public void rejectDuplicatedLaneInMultiplePool() {
    Pool pool1 = new Pool();
    Pool pool2 = new Pool();
    Pool pool3 = new Pool();
    Lane lane = new Lane();
    Assert.assertTrue(pool1.addLane(lane));
    pool1.mute();
    pool2.mute();
    pool3.mute();
    lane.mute();
    Assert.assertFalse(((Pool) pool2.mute()).addLane(lane));
    Assert.assertFalse(((Pool) pool2.mute()).includes(lane));
    Assert.assertFalse(((Pool) pool3.mute()).addLane(lane));
    Assert.assertFalse(((Pool) pool3.mute()).includes(lane));
  }

  @Test
  public void rejectLaneInSingleLanePool() {
    Pool pool = new Pool();
    Task task = new Task();
    Assert.assertNotNull(task);
    Assert.assertTrue(pool.addElement(task));
    Lane lane = new Lane();
    pool.mute();
    task.mute();
    lane.mute();
    Assert.assertFalse(((Pool) pool.mute()).addLane(lane));
    Assert.assertFalse(((Pool) pool.mute()).includes(lane));
  }

  @Test
  public void rejectElementInMultipleLanePool() {
    Pool pool = new Pool();
    Lane lane = new Lane();
    Assert.assertTrue(pool.addLane(lane));
    Task task = new Task();
    Assert.assertNotNull(task);
    pool.mute();
    lane.mute();
    task.mute();
    Assert.assertFalse(((Pool) pool.mute()).addElement(task));
    Assert.assertFalse(((Pool) pool.mute()).includes(task));
  }

  @Test
  public void rejectNonLaneElementInPool() {
    Pool pool = new Pool();
    Task task = new Task();
    pool.mute();
    task.mute();
    Assert.assertFalse(((Pool) pool.mute()).addLane(task));
    Assert.assertFalse(((Pool) pool.mute()).includes(task));
  }
}
